package org.zoomdev.zoom.protobuf.modules;

import io.protostuff.ByteArrayInput;
import io.protostuff.ProtostuffOutput;

import java.io.IOException;

public class IUnknownSchema implements ISchema {
    public static final IUnknownSchema IUnknownSchema = new IUnknownSchema();

    @Override
    public void write(ProtostuffOutput output, int index, Object value, boolean repeat) throws IOException {
        if (value == null) {
            return;
        }
        ISchema schema = IUnknownSchemaRegistry.getSchema(value.getClass());
        schema.write(output, 1, value, false);
    }

    @Override
    public Object mergeFrom(ByteArrayInput input) throws IOException {
        input.readFieldNumber(null);
        int index = input.readInt32();
        ISchema schema = IUnknownSchemaRegistry.getSchema(index);
        return schema.mergeFrom(input);
    }
}
